import numpy as np
import pandas as pd
from pandas import Series,DataFrame

from datetime import datetime
from datetime import timedelta

now = datetime.now()
print type(now), now
print now.year, now.month, now.day

delta = datetime(2011, 1, 7) -datetime(2008, 6,24, 8, 15)
print delta
# print datetime.timedelta(926, 56700)
print delta.days
print delta.seconds

start = datetime(2011, 1, 7)
print start + timedelta(12)
print start + timedelta(2011, 1, 19, 0, 0)

print "---------------------1------------------"
stmp = datetime(2001, 1, 3)
print str(stmp)
print stmp.strftime('%Y-%m-%d')
value = '2011-01-03'
print datetime.strptime(value, '%Y-%m-%d')
print datetime(2011, 1, 3, 0,0), type(datetime(2011, 1, 3, 0,0))

datestrs = ['7/6/2011', '8/6/2011']
print [datetime.strptime(x, '%m/%d/%Y') for x in datestrs]

print "-----------------2-------------------------"
from dateutil.parser import parse
print parse('2011-01-03'), type(parse('2011-01-03'))
print parse('Jan 31, 1997 10:45 PM'), type(parse('Jan 31, 1997 10:45 PM'))
print parse('6/12/2011', dayfirst=True)

print "--------------------------3-------------------------"
print pd.to_datetime(datestrs)


index = pd.date_range('4/1/2012', '6/1/2012')
print index
print pd.date_range('4/1/2012', periods=20)
print pd.date_range('1/1/2000', '12/1/2000', freq='BM')

print "---------------------------4---------------------------"
from pandas.tseries.offsets import Hour, Minute
hour = Hour()
print hour
four_hours = Hour(4)
print four_hours
print pd.date_range('1/1/2000', '1/3/2000', freq='4h')

print "-------------------------5-------------------------------"
ts = Series(np.random.randn(4), index=pd.date_range('1/1/2000', periods=4, freq='M'))
print ts
print ts.shift(2)
print ts.shift(-2)
print ts / ts.shift(1)
print ts / ts.shift(1) -1
print ts.shift(2, freq='M')